package com.LeetCode.dp.shares;

import org.junit.Test;

/**
 * 股票第一题，只能一次买卖
 */
public class shares_1 {

    public int maxProfit(int[] prices) {
        int curMin = Integer.MAX_VALUE;
        int ans = 0;
        for(int i=0; i<prices.length; i++){
            curMin = Math.min(curMin, prices[i]);
            ans = Math.max(ans, prices[i] - curMin);
        }
        return ans;
    }

    @Test
    public void test(){
        int[] prices = {7,1,5,3,6,4};
        System.out.println(maxProfit(prices));
    }
}
